package DataStructures;
import java.util.ArrayList;

/**
 * This class adds the functionality to Player that is needed for poker. That is, interacting with chips and cards
 * TODO: should this have functions for the dealer button?
 * @author Phil
 *
 */
public class PokerPlayer extends Player {	
	private int chips;	
	private ArrayList<Card> cards;
	
	public PokerPlayer(){
		super();
		chips = 0;		
		cards = new ArrayList<Card>();
	}	
	
	//***********
	// Section for interacting with the players chips
	//**********	
	public void setChips(int chips){
		if(chips >= 0){
			this.chips = chips;
		}else{
			// A player cannot have negative chips? Therefore set it to 0
			// Maybe throw an exception here.. not sure
			//throw new NegativeChipException("yayyay");
			this.chips = 0;
		}
	}
	
	public int getChipCount(){
		return this.chips;
	}
	
	/**
	 * Attempt to take an amount of chips from the player, if the player cannot fulfill the 
	 * request take all their remaining chips
	 * @param amount
	 * @return the amount of chips taken from the player
	 */
	public int removeChips(int amount){
		int amountRemoved = 0;
		if(chips - amount >= 0){
			this.chips -= amount;
			amountRemoved = amount;
		}else {
			// Cannot go into negative chips... consider throwing an exception here?
			amountRemoved = chips;
			chips = 0;			
		}
		return amountRemoved;
	}
	
	public void addChips(int amount){
		this.chips += amount;
		//TODO: check for integer overflow
	}
	
	//***********
	// Section for interacting with the players hand
	//**********
	public void setHand(ArrayList<Card> cards){
		this.cards = cards;
	}
	
	public ArrayList<Card> getHand(){
		return this.cards;
	}
	
	public void clearHand(){
		this.cards.clear();
	}
	
	/**
	 * A PokerPlayer can only have two cards, if the player has 2 cards and another card is to be added
	 * discard the new card (TODO: make this better)
	 */
	public void addCard(Card c){
		if(this.cards.size() >= 0 && this.cards.size() < 3){
			this.cards.add(c);
		}
	}
	
	public class NegativeChipException extends Exception{
		
		private String message;
		
		public NegativeChipException(String message){
			this.message = message;
		}
		
	}
}


